/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package coverter;

import entities.Area;
import entities.Dependencia;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author Agapo
 */
@FacesConverter("dependenciaConverter")
public class DependenciaConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Dependencia d = new Dependencia();
        String cad[] = value.split("__");
        Area a = new Area();
        a.setIdArea(Integer.parseInt(cad[0]));
        a.setTipo(cad[1]);
        d.setIdDependencia(Integer.parseInt(cad[2]));
        d.setDependencia(cad[3]);
        return d;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Dependencia d = (Dependencia) value;
        String cad = d.getIdArea().getIdArea() + "__" + d.getIdArea().getTipo() + "__" + d.getIdDependencia() + "__" + d.getDependencia();
        return cad;
    }
}
